<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ToDoList</title>
    <link rel="stylesheet" href="./index.css">
    <script src="./vue.global.js"></script>
</head>
<body>
    <div id="app">
        <div class="head">
            <div class="head-box">
                <h2>ToDoList</h2>
                <input v-model="newTodo" @keyup.enter="add" type="text" placeholder="添加ToDo">
            </div>
        </div>
        <div class="list">
            <div class="list-head">
                <h2>正在完成</h2>
                <div class="count">{{ todo_list.length }}</div>
            </div>
            <ul>
                <li v-for="(todo, index) in todo_list" :key="index">{{ todo }}</li>
            </ul>
        </div>
        <div class="list">
            <div class="list-head">
                <h2>已经完成</h2>
                <div class="count">0</div>
            </div>
            <ul>
                <li v-for="(todo, index) in completedTodos" :key="index">{{ todo }}</li>
            </ul>
        </div>
    </div>

    <script>
        const app = Vue.createApp({
            data() {
                return {
                    todo_list: [],
                    newTodo: ''
                };
            },
            methods: {
                add() {
                    if (this.newTodo.trim()) {
                        this.todo_list.push(this.newTodo);
                        this.newTodo = ''; // 清空输入框
                    }
                }
            }
        });
        app.mount("#app");
    </script>
</body>
</html>